package com.dcbeida.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.Stock;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 入库详情
 */
public class RkSocketAdapter extends BaseAdapter {

    private ArrayList<Stock.ListBean.DrugsBean> mArrayList = new ArrayList<>();
    private Context mContext;

    public RkSocketAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d("TAG", "getView: ");
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.has_big_title_with_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Stock.ListBean.DrugsBean bean = mArrayList.get(position);
        if (bean.isFirst())
            holder.lin_item_head.setVisibility(View.VISIBLE);
        else
            holder.lin_item_head.setVisibility(View.GONE);

        holder.tv_yp_name.setText(bean.getDrugName());
        holder.tv_count.setText(bean.getCount()+"");


        holder.tvBh.setText(bean.getDrugcode());
        holder.tvYxq.setText(mContext.getString(R.string.yxq) + bean.getExpiredate());
        holder.tvBox.setText(bean.getQuantity() + "");
        holder.tvPh.setText(bean.getBatchnumber() + "");

        return convertView;
    }


    public ArrayList<Stock.ListBean.DrugsBean> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(List<Stock.ListBean.DrugsBean> mArrayList) {
        if (mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }

    public void clearList() {
        this.mArrayList.clear();
    }



    static class ViewHolder {
        @Bind(R.id.tv_ph)
        TextView tvPh;
        @Bind(R.id.tv_yxq)
        TextView tvYxq;
        @Bind(R.id.tv_bh)
        TextView tvBh;
        @Bind(R.id.tv_box)
        TextView tvBox;

        @Bind(R.id.lin_item_head)
        LinearLayout lin_item_head;
        @Bind(R.id.tv_yp_name)
        TextView tv_yp_name;
        @Bind(R.id.tv_count)
        TextView tv_count;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
